package com.cloudsigns.factorymanager2.engineering.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringInstallationOrderBean;
import com.cloudsigns.factorymanager2.engineering.bean.OrderParentBean;
import com.cloudsigns.factorymanager2.engineering.presenter.TeamReceiveOrBackEngineeringInstallOrderPresenter;
import com.cloudsigns.factorymanager2.event.EngineeringOrderDetailForTeamEvent;
import com.cloudsigns.factorymanager2.project.adapter.ProductInformationAdapter;
import com.cloudsigns.factorymanager2.project.bean.ProductBean;
import com.cloudsigns.factorymanager2.project.utils.DateUtil;

import java.util.ArrayList;
import java.util.List;

import de.greenrobot.event.EventBus;

/**
 * Created by tony on 2018/5/10.
 */

public class EngineeringInstallWorkOrderInfoForSuperFragment extends Fragment implements View.OnClickListener {
    private final String TAG = EngineeringInstallWorkOrderInfoForSuperFragment.class.getSimpleName();
    private TextView tv_project_name, tv_engineering_name;
    private TextView edt_engineering_address, edt_install_cycle;
    private TextView edt_dispath_order_person_colon, edt_dispath_order_time_colon, edt_receive_people_colon, edt_reception_time_colon;
    private View rl_project;
    private View ll_receive_back_btn;
    private CommonEnum.STATUS status;
    private ListView lv;
    private LinearLayout ll_engineering_info_content;
    private ImageView img_project_select;
    private ProductInformationAdapter adapter;
    private List<ProductBean> productBeanList = new ArrayList<>();
    EngineeringInstallationOrderBean engineeringInstallationOrderBean;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_engineeringinstall_workorderinfo_for_super, null);

        tv_project_name = view.findViewById(R.id.tv_project_name);
        tv_engineering_name = view.findViewById(R.id.tv_engineering_name);
        edt_install_cycle = view.findViewById(R.id.edt_install_cycle);
        edt_engineering_address = view.findViewById(R.id.edt_engineering_address);
        edt_dispath_order_person_colon = view.findViewById(R.id.edt_dispath_order_person_colon);
        edt_dispath_order_time_colon = view.findViewById(R.id.edt_dispath_order_time_colon);
        edt_receive_people_colon = view.findViewById(R.id.edt_receive_people_colon);
        edt_reception_time_colon = view.findViewById(R.id.edt_reception_time_colon);
        ll_receive_back_btn = view.findViewById(R.id.ll_receive_back_btn);

        ll_receive_back_btn.setVisibility(View.GONE);

        lv = view.findViewById(R.id.lv);
        ll_engineering_info_content = view.findViewById(R.id.ll_engineering_info_content);
        img_project_select = view.findViewById(R.id.img_project_select);
        rl_project = view.findViewById(R.id.rl_project);


        img_project_select.setBackgroundResource(R.mipmap.arrow_down_icon);
        rl_project.setOnClickListener(this);


        adapter = new ProductInformationAdapter(getActivity(), TAG);
        adapter.setData(productBeanList);
        lv.setAdapter(adapter);

        return view;
    }


    public void initData(EngineeringInstallationOrderBean engineeringInstallationOrderBean) {
        if (null != engineeringInstallationOrderBean) {
            this.engineeringInstallationOrderBean = engineeringInstallationOrderBean;

            tv_project_name.setText(engineeringInstallationOrderBean.getProjectName());
            tv_engineering_name.setText("/" + engineeringInstallationOrderBean.getEngineeringName());
            edt_engineering_address.setText(engineeringInstallationOrderBean.getEngineeringAddress());
            edt_install_cycle.setText(DateUtil.getYyyy_Mm_Dd(engineeringInstallationOrderBean.getBeginDate()) + "/" + DateUtil.getYyyy_Mm_Dd(engineeringInstallationOrderBean.getCompleteDate()));
            edt_dispath_order_person_colon.setText(engineeringInstallationOrderBean.getCreateOrderAccountName() + ":" + engineeringInstallationOrderBean.getCreateOrderAccountId());
            edt_dispath_order_time_colon.setText(DateUtil.getYyyy_Mm_Dd(engineeringInstallationOrderBean.getSendOrderTime()));
            edt_receive_people_colon.setText(engineeringInstallationOrderBean.getReceiveAccountName() + ":" + engineeringInstallationOrderBean.getReceiveAccountId());
            edt_reception_time_colon.setText(DateUtil.getYyyy_Mm_Dd(engineeringInstallationOrderBean.getReceiveOrderTime()));

            if (null != engineeringInstallationOrderBean.getProductList()) {
                productBeanList.addAll(engineeringInstallationOrderBean.getProductList());
                adapter.setData(productBeanList);
                adapter.notifyDataSetChanged();
            }
        }

    }


    private void showEngineeringInfoDialog() {
        if (ll_engineering_info_content.getVisibility() == View.VISIBLE) {
            ll_engineering_info_content.setVisibility(View.GONE);
            img_project_select.setBackgroundResource(R.mipmap.arrow_down_icon);
        } else {
            ll_engineering_info_content.setVisibility(View.VISIBLE);
            img_project_select.setBackgroundResource(R.mipmap.arrow_top);
        }
    }


    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.rl_project:
                showEngineeringInfoDialog();
                break;


        }
    }


}
